<?php
include("general_include.php");
include "top.php";
include "left.php";


if(isset($_GET['error'])) $_SESSION['error_forum'] = $_GET['error'];
if(isset($_GET['username'])) $_SESSION['forum_username'] = $_GET['username'];

if(isset($_POST['submit']))
{
   $Formval = $_POST;
   $game_id = $_POST['game_id'];
   $experience = $_POST['experience'];
   
   $userSql="SELECT * FROM ".TABLEPREFIX."_user where user_id='".$_SESSION['new_reg_id']."'";
   $record = $UserManagerObjAjax->GetRecords("Row",$userSql);
   
   $Sql= "INSERT INTO ".TABLEPREFIX."_user_game set game_id='$game_id',experience='".addslashes($experience)."',
   comment='".addslashes($comment)."',is_active='Y',user_type_id='2',user_id='".$_SESSION['new_reg_id']."',date_added='".date("Y-m-d")."'";
   //die($Sql);
   $UserManagerObjAjax->Execute($Sql);
   
   $ContactSql = "SELECT admin_email FROM ".TABLEPREFIX."_admin WHERE  admin_id=1";
   $Contact_email = $UserManagerObjAjax->GetRecords("Row",$ContactSql);
   $admin_email=$Contact_email['admin_email'];
   
   
   if(!mysql_error())
   {
                $tpl_file="email_templates/register_mail.html";
				$tpl_handler=fopen($tpl_file,"r");
				$tpl_message=fread($tpl_handler,filesize($tpl_file));
				fclose($tpl_handler);
			
				    //$fromEmail	= "NOOBSKOOL Admin";
				    $to			= $record['email'];
			
			        $message = "Welcome to our site. You can access your account by using your email id and given password. <br /> Your login information is given bellow<br />
				    Email : ".$record['email']." and Password : ".$record['password']; 
					$url=$site_url;
					$tpl_message=str_replace("[SITEURL]",$url,$tpl_message);
					$tpl_message=str_replace("[HEADING]",$record['name'],$tpl_message);
					$tpl_message=str_replace("[MESSAGE]",$message,$tpl_message);
					
					$headers  = 'MIME-Version: 1.0' . "\r\n";
					$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
					$headers .= 'From:'.$admin_email . "\r\n" .
									'X-Mailer: PHP/' . phpversion();
					
					mail($to, 'Sucessfull Registration', $tpl_message, $headers);
				
/*					$mail = new PHPMailer;
					$mail->FromName = "NOOBSKOOL Admin";
					$mail->From    =  $fromEmail;
					$mail->Subject =  "Sucessfull Registration";
					$mail->Body    = stripslashes($tpl_message);
					$mail->IsHTML(true);
					$mail->AddAddress($to,$to);
					
				    if($_SERVER['HTTP_HOST'] !='10.10.0.100')
				    $mail->Send();
*/					unset($_SESSION['new_reg_id']);
					echo "<script>window.location.href='registration_success.php'</script>";
				exit;  
				
    }

}



$gameSql = "SELECT game_id,game_name FROM ".TABLEPREFIX."_game where is_active='Y' ORDER BY game_name";
$GameArr = $UserManagerObjAjax->HtmlOptionArrayCreate($gameSql);
	
$smarty->assign('Formval',$Formval);
$smarty->assign('GameArr',$GameArr);

$smarty->display("registration-student.tpl");
include("footer.php");
?>